//待发货
	function getCookie(cookieName) {
    var strCookie = document.cookie;
    var arrCookie = strCookie.split("; ");
    for(var i = 0; i < arrCookie.length; i++){
        var arr = arrCookie[i].split("=");
        if(cookieName == arr[0]){
            return arr[1];
        }
    }
    return "";
}
var page = 0;
var offset = 0;
var pageSize = 5;
var j=5;

var userid=getCookie("userid");


	function delivercha(){
		
		taiochas()
		$.ajax({
			url:"http://localhost:16111/orderform/delivercha",
			mimeType: "post",
			dataType: "json",
			data:{
				q:0,
				j:j,
				userid:userid
				
			},
			xhrFields:{withCredentials: true},
			success:function(date){
				
				var str="";
				for(i in date){
					var time=new Date(date[i].undertime);
					var time2=time.getFullYear()+"-"+time.getMonth()+"-"+time.getDay();
					
				str+="<tr class='order-item'>"+
					"<td>"+
						"<label>"+
							"<a href='udai_order_detail.html' class='num'>"+time2+"订单号:" +date[i].ordernumber +"</a>"+
							"<div class='card'>"+
								"<div class='img'><img src="+ date[i].comitypicture +" alt='' class='cover'></div>"+
								"<div class='name ep2'>" +date[i].comitydescription + "</div>"+
								"<div class='format'>颜色/尺码：" +date[i].specifications+ "</div>"+
								"<div class='favour'>使用" +date[i].preferentialinformation +"</div>"+
							"</div>"+
						"</label>"+
					"</td>"+
					"<td>￥"+date[i].comityprices + "</td>"+
					"<td>"+date[i].comitynumber + "</td>"+
					"<td>￥"+date[i].actualpayment + "<br><span class='fz12 c6 text-nowrap'>(含运费: ¥" +date[i].freight + ")</span></td>"+
					"<td class='state'>"+
						"<a class='but c6'>" +date[i].orderstatus + "</a>"+
						"<a href='udai_order_detail.html?id="+date[i].orderid+"' class='but c9'>订单详情</a>"+
					"</td>"+
					"<td class='order'>"+
						"<div class='del'><span class='glyphicon glyphicon-trash' aria-hidden='true'></span></div>"+
						 "<a href='udai_apply_return.html'  onclick='chuan(\"" + date[i].ordernumber + "\",\"" + date[i].actualpayment + "\")'  class='but but-primary'>"+date[i].statusbutton+"</a>"+
					"</td>"+
				"</tr>";
				}
				
				document.getElementById("delivercha").innerHTML = str;
			},
		});
	}
	
	

		function taiochas(){
			$.ajax({
			url: "http://localhost:16111/orderform/taiochasss",
			mimeType: "post",
			dataType: "json",
			data:{
				userid:userid,
			},
			xhrFields:{withCredentials: true},
			success: function(date){
				document.getElementById("articlesss").innerHTML =date;
			},
			});
		}
		
	
		
		//分页
		function sanss(){
			if(offset-pageSize<0){
						alert("没有上一页");
						return;
					}else{
						offset=offset-pageSize;
						page=page+1;
					} 
			var str="";
			$.ajax({
				url: "http://localhost:16111/orderform/delivercha",
				mimeType: "post",
				dataType: "json",
				data:{
					q:offset,
					j:j,
					userid:userid
				},
				xhrFields:{withCredentials: true},
				success:function(date){
					var str="";
					console.log(date);
					for(i in date){
						var time=new Date(date[i].undertime);
							var time2=time.getFullYear()+"-"+time.getMonth()+"-"+time.getDay();
							
						str+="<tr class='order-item'>"+
							"<td>"+
								"<label>"+
									"<a href='udai_order_detail.html' class='num'>"+time2+"订单号:" +date[i].ordernumber +"</a>"+
									"<div class='card'>"+
										"<div class='img'><img src="+ date[i].comitypicture +" alt='' class='cover'></div>"+
										"<div class='name ep2'>" +date[i].comitydescription + "</div>"+
										"<div class='format'>颜色/尺码：" +date[i].specifications+ "</div>"+
										"<div class='favour'>使用" +date[i].preferentialinformation +"</div>"+
									"</div>"+
								"</label>"+
							"</td>"+
							"<td>￥"+date[i].comityprices + "</td>"+
							"<td>"+date[i].comitynumber + "</td>"+
							"<td>￥"+date[i].actualpayment + "<br><span class='fz12 c6 text-nowrap'>(含运费: ¥" +date[i].freight + ")</span></td>"+
							"<td class='state'>"+
								"<a class='but c6'>" +date[i].orderstatus + "</a>"+
								"<a href='udai_order_detail.html?id="+date[i].orderid+"' class='but c9'>订单详情</a>"+
							"</td>"+
							"<td class='order'>"+
								"<div class='del'><span class='glyphicon glyphicon-trash' aria-hidden='true'></span></div>"+
								
								 "<a href='udai_apply_return.html'  onclick='chuan(\"" + date[i].ordernumber + "\",\"" + date[i].actualpayment + "\")'  class='but but-primary'>"+date[i].statusbutton+"</a>"+
							"</td>"+
						"</tr>";
					}
					document.getElementById("delivercha").innerHTML = str;
				},
				
			})
		}
		
		
		function xiaoss(){
			
			if(page==2){
				alert("没有下一页");
				return;
				}else{
				offset=offset+pageSize;
				page=page-1;
						} 
			
			$.ajax({
				url: "http://localhost:16111/orderform/delivercha",
				mimeType: "post",
				dataType: "json",
				data:{
					q:offset,
					j:j,
					userid:userid
				},
				xhrFields:{withCredentials: true},
				success:function(date){
					
					var str="";
					for(i in date){
						var time=new Date(date[i].undertime);
							var time2=time.getFullYear()+"-"+time.getMonth()+"-"+time.getDay();
							var str="";
						str+="<tr class='order-item'>"+
							"<td>"+
								"<label>"+
									"<a href='udai_order_detail.html' class='num'>"+time2+"订单号:" +date[i].ordernumber +"</a>"+
									"<div class='card'>"+
										"<div class='img'><img src="+ date[i].comitypicture +" alt='' class='cover'></div>"+
										"<div class='name ep2'>" +date[i].comitydescription + "</div>"+
										"<div class='format'>颜色/尺码：" +date[i].specifications+ "</div>"+
										"<div class='favour'>使用" +date[i].preferentialinformation +"</div>"+
									"</div>"+
								"</label>"+
							"</td>"+
							"<td>￥"+date[i].comityprices + "</td>"+
							"<td>"+date[i].comitynumber + "</td>"+
							"<td>￥"+date[i].actualpayment + "<br><span class='fz12 c6 text-nowrap'>(含运费: ¥" +date[i].freight + ")</span></td>"+
							"<td class='state'>"+
								"<a class='but c6'>" +date[i].orderstatus + "</a>"+
								"<a href='udai_order_detail.html?id="+date[i].orderid+"' class='but c9'>订单详情</a>"+
							"</td>"+
							"<td class='order'>"+
								"<div class='del'><span class='glyphicon glyphicon-trash' aria-hidden='true'></span></div>"+
								"<a  class='but c3'>买家已付款</a>"+
								 "<a href='udai_apply_return.html'  onclick='chuan(\"" + date[i].ordernumber + "\",\"" + date[i].actualpayment + "\")'  class='but but-primary'>"+date[i].statusbutton+"</a>"+
							"</td>"+
						"</tr>";
					}
					document.getElementById("delivercha").innerHTML = str;
				},
				
			})
		}
		
		function chuan(ordernumber,actualpayment){
				localStorage.setItem("ordernumber",ordernumber);
				localStorage.setItem("actualpayment",actualpayment);
			}
		
		  
		function chuancha(){
			
			var ordernumber =localStorage.getItem("ordernumber");
			var actualpayment =localStorage.getItem("actualpayment");
				$.ajax({
					url:"http://localhost:16111/orderform/mhselenumber",
					mimeType: "post",
					dataType: "json",
					data:{
						 ordernumber:ordernumber,
						},
						xhrFields:{withCredentials: true},
					success:function(date){
						var str="";
						for(i in date){					
						str+="<div class='return-item__info'>"+
						"<div class='img' id='picture'>"+
						"<img src="+date[i].comitypicture+"  class='cover'></div>"+
						"<div class='name ep2' id='shoopname'>"+date[i].comitydescription+"</div>"+
						"<div class='type' id='ordercolor'>" +date[i].specifications+ " </div>"+
						"<div class='num' id='ordernumber'>" +ordernumber+"</div>"+
						"</div>";
						document.getElementById("price").innerHTML=actualpayment;
						}
						
						document.getElementById("chuancha").innerHTML = str;
					},
				})
			};
		
		
		
		function gai(){
			var arr =localStorage.getItem("ordernumber");
			
			$.ajax({
			url: "http://localhost:16111/orderform/tuikuang",
			method: "post",
			dataType: "json",
			 data:{
				 ordernumber:arr
				},
				xhrFields:{withCredentials: true},
					success: function(data) {
					alert("修改成功");
				},
						error: function(text) {
							var json = eval(text);
							alert(text.toString()+"111");
							
						}
					})
					}
					
				
					function addordertow(){
						
										var ordernumber = document.getElementById("ordernumber").innerHTML;

										var userid=getCookie("userid");

										var servicetype = document.getElementById("servicetype").value;
										var cargostatus = document.getElementById("cargostatus").value;
										var price = document.getElementById("price").innerHTML;
										var refundreason = document.getElementById("refundreason").value;
										var refundinstructions = document.getElementById("refundinstructions").value;
										var shoopname = document.getElementById("shoopname").innerHTML;
										var ordercolor = document.getElementById("ordercolor").innerHTML;
										var picture = document.getElementById("picture").innerHTML;
										
										$.ajax({
											mimeType:"post",
											url:"http://localhost:16111/orderform/addordertow",
										    dataType: "json",
											data:{userid:userid,ordernumber:ordernumber,servicetype:servicetype,cargostatus:cargostatus,price:price,refundreason:refundreason,refundinstructions:refundinstructions,shoopname:shoopname,ordercolor:ordercolor,picture:picture},	
											 xhrFields:{withCredentials: true},
											success:function(date)
											{
												
												if(date==1)
												{
													alert("退款申请成功")
													gai();
											}else
												{
													alert("退款申请失败")
												}
											}
											});
									}
		
		
		//查询退款订单
		function requestData(){
					  $.ajax({
			          url: "http://localhost:16111/orderform/tuikuancha",
			          type: "post",
			          dataType: "json",
					  data:{
						  userid:userid
					  },
					  xhrFields:{withCredentials: true},
			          success: function(data){
			              /*这个方法里是ajax发送请求成功之后执行的代码*/
			              showData(data);//我们仅做数据展示
			          },
			         error: function(msg){
			             alert("ajax连接异常："+msg);
			        }
			     });
			 }
			 
				function showData(data) {
			     var str = "";//定义用于拼接的字符串
				 
			      for (var i = 0; i < data.length; i++) {
					  var time=new Date(data[i].updatime);
					  var time2=time.getFullYear()+"-"+time.getMonth()+"-"+time.getDay();
			          //拼接表格的行和列
			          str = "<tr><td>" + data[i].ordernumber + "</td><td>" + data[i].ordernumber + "</td><td>" + data[i].shoopname + "</td><td>" +time2+ "</td><td>" + data[i].price + "</td><td>" + data[i].tkstatus + "</td><td>" + data[i].tkstatus + "</td></tr>";
			          //追加到table中
			          $("#tab").append(str);
							   }
					}